<template>
  <div>
    <basic-container>
      <avue-tree-table :option="option" v-model="shopClass" :data="data" ref="crud"
                       @current-change="handleCurrentChange"
                       @row-save="handleSave"
                       @row-update="handleUpdate"
                       @row-del="handleDel">
        <el-table-column label="操作" width="255" min-width="255">
          <template slot-scope="scope">
            <el-button type="primary" @click.stop="handleAdd(shopClass.row)">添加</el-button>

            <el-button type="info" @click.stop="handleRowEdit(shopClass.row)">修改</el-button>

            <el-button type="danger" @click.stop="handleRowDel(shopClass.row)">删除</el-button>
          </template>
        </el-table-column>
      </avue-tree-table>
    </basic-container>
  </div>
</template>

<script>
  import {treeList,getPageList,add,edit,del} from '@/api/shop/ShopClass/ShopClass';
  import { validatenull } from '@/util/validate';
  import { mapGetters } from "vuex";
  import { shopClassOption } from "@/const/shop/ShopClass/ShopClassTableOption.js";
  import { classOption } from "@/const/shop/ShopClass/ClassOption.js";
  export default {
    name: "tableTree",
    components: {},
    data () {
      return {
        form:{},
        shopClass:{},
        data:[],
        option:classOption
      };
    },
    created () {
      this.handleList();
    },
    watch: {},
    mounted () { },
    computed: {
      ...mapGetters(["permission", "menuAll"])
    },
    methods: {
      /**
       * @title 获取字典
       * @detail 调用crud的findByvalue方法即可
       *
       **/
      findByvalue (dic, value) {
        return this.$refs.crud.findByvalue(dic, value);
      },
      handleList () {
        treeList().then(res => {
          this.data = res.data.data;
        });

      },
      /**
       * @title 数据添加
       *
       **/
      handleAdd () {
        this.$refs.crud.rowAdd();
      },
      /**
       * @title 数据添加
       * @param row 为当前的数据
       * @param done 为表单关闭函数
       *
       **/
      handleSave (row, done) {
        add(row).then(res => {
          console.log(this.page.currentPage);
          this.handleList();
          this.$message({
            showClose: true,
            message: "添加成功",
            type: "success"
          });
          done();
        })
      },
      /**
       * @title 数据更新
       *
       **/
      handleRowEdit (row, index) {
        this.$refs.crud.rowEdit(row, index);
      },
      /**
       * @title 数据更新
       * @param row 为当前的数据
       * @param index 为当前更新数据的行数
       * @param done 为表单关闭函数
       *
       **/
      handleUpdate (row, index, done) {
        edit(row).then(res => {
          this.handleList();
          this.$message({
            showClose: true,
            message: "修改成功",
            type: "success"
          });
          done();
        })
      },
      /**
       * @title 数据删除
       * @param row 为当前的数据
       * @param index 为当前更新数据的行数
       *
       **/
      handleRowDel (row, index) {
        this.$confirm(`是否确认删除序号为${row.name}`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
                .then(() => {
                  this.tableData.splice(index, 1);
                  this.$notify({
                    showClose: true,
                    message: '删除成功',
                    type: 'success',
                  });
                })
                .catch(() => { });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .table-container {
    padding: 8px 10px;
  }
</style>

